'use strict';

describe('templateDataFilter', function() {
  var $template;
  beforeEach(module('fbdApp.templateModule'));
  beforeEach(inject(function(_$filter_) {
    $template = _$filter_('templateFilter');
  }));

  it('should be defined', function(done) {
    expect($template).toBeDefined();
    return done();
  });

  var rules = [{
      mode: 'signs',
      beginText: '<<<',
      type: 1,
      expression: '123',
      name: 'rule1'
    }, {
      mode: 'signs',
      beginText: '<<<',
      endText: 'a',
      type: 2,
      expression: '12312',
      name: 'rule2'
    }, {
      mode: 'signs',
      beginText: '<<<',
      endText: 'a',
      type: 2,
      expression: '12312',
      name: 'rule3'
    },
    [{
      mode: 'signs',
      beginText: '<<<',
      type: 1,
      expression: '123',
      name: 'sub1'
    }, {
      mode: 'signs',
      beginText: '<<<',
      type: 1,
      expression: '123',
      name: 'sub2'
    }]
  ];

  var text = {
    type: 'file',
    content: 'abc.fbd'
  };

  var expected = {
    text: {
      type: 'file',
      content: 'abc.fbd'
    },
    template: {
      rules: {
        rule1: {
          mode: 'signs',
          beginText: '<<<',
          type: 1,
          expression: '123',
          name: 'rule1',
          subset: {
            rules: {
              rule2: {
                mode: 'signs',
                beginText: '<<<',
                endText: 'a',
                type: 2,
                expression: '12312',
                name: 'rule2'
              },
              rule3: {
                mode: 'signs',
                beginText: '<<<',
                endText: 'a',
                type: 2,
                expression: '12312',
                name: 'rule3'
              },
              sub1: {
                mode: 'signs',
                beginText: '<<<',
                type: 1,
                expression: '123',
                name: 'sub1',
                subset: {
                  rules: {
                    sub2: {
                      mode: 'signs',
                      beginText: '<<<',
                      type: 1,
                      expression: '123',
                      name: 'sub2'
                    }
                  },
                  includes: ['sub2'],
                  before: [],
                  after: [],
                  require: ['sub2']
                }
              }
            },
            includes: ['rule2', 'rule3', 'sub1'],
            before: [],
            after: ['sub1'],
            require: ['rule2', 'rule3']
          }
        }
      },
      includes: ['rule1'],
      before: [],
      after: [],
      require: ['rule1']
    }
  };

  it('test result', function(done) {

    expect($template(rules, text)).toEqual(expected);
    return done();
  });


});
